﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Comom.Project.ControllerCom;
using Dhtl.Service.IService;
using dai_hoc_tuong_lai.Areas.Admin.Models;

namespace dai_hoc_tuong_lai.Controllers
{
    public class AnhDepController : UTController
    {
        //
        // GET: /AnhDep/
        private readonly IAlbum _iDichvu;
        private readonly ICateAlbum _iCateDichvu;
        private readonly int  PageSize = 15;

        public AnhDepController(IAlbum iDichvu, ICateAlbum iCateDichvu)
        {
            this._iCateDichvu = iCateDichvu;
            this._iDichvu = iDichvu;
        }

        public ActionResult MenuAnhdep(int parent)
        {
            var listEntity = _iCateDichvu.List();
            List<CateAlbumModel> model = new List<CateAlbumModel>();
            try
            {
                foreach (var item in listEntity)
                {
                    CateAlbumModel ml = new CateAlbumModel();
                    CateAlbumModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }
            ViewBag.parent = parent;

            return PartialView("_MenuAnhdep", model);
        }

        public ActionResult List()
        {

            var listEntity = _iDichvu.List();
            List<AlbumModel> model = new List<AlbumModel>();
            try
            {
                if(listEntity.Count() > 10) listEntity = listEntity.Take(10).ToList();
                foreach (var item in listEntity)
                {
                    AlbumModel ml = new AlbumModel();
                    AlbumModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }

            return PartialView("_List", model);
        }

        public ActionResult ListByCate(int id)
        {

            var listEntity = _iDichvu.ListByCatetId(id);
            List<AlbumModel> model = new List<AlbumModel>();
            try
            {
                foreach (var item in listEntity)
                {
                    AlbumModel ml = new AlbumModel();
                    AlbumModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }

            return PartialView("_ListByCate", model);
        }

        public ActionResult Index(int id, string name)
        {


            CateAlbumModel model = new CateAlbumModel();
            var entity = _iCateDichvu.GetById(id);
            try
            {
                CateAlbumModel.MapFrom(entity, ref model);
            }
            catch { }

            return View(model);
        }

    }
}
